package com.eascs.banknet.common.config;

import javax.servlet.Filter;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;

import org.jasig.cas.client.session.SingleSignOutFilter;
import org.jasig.cas.client.session.SingleSignOutHttpSessionListener;
import org.jasig.cas.client.util.AssertionThreadLocalFilter;
import org.jasig.cas.client.util.HttpServletRequestWrapperFilter;

import com.eascs.web.AbstractApplicationInitializer;
import com.eascs.web.sso.Cas20ProxyReceivingTicketValidationFilter;
import com.eascs.web.sso.EAAuthenticationFilter;

public class ApplicationInitializer extends AbstractApplicationInitializer {
	@Override
	protected Class<?>[] getRootConfigClasses() {
		return new Class[] { AppConfig.class };
	}

	@Override
	protected Class<?>[] getServletConfigClasses() {
		return new Class[] { WebConfig.class };
	}

	@Override
	protected String[] getServletMappings() {
		return new String[] { "/" };
	}

	@Override
	protected Filter[] getServletFilters() {
		return super.getServletFilters();
	}

	@Override
	public void onStartup(ServletContext servletContext) throws ServletException {
		super.onStartup(servletContext);
//		addSso(servletContext);
	}

	private void addSso(ServletContext servletContext) {
		servletContext.addListener(SingleSignOutHttpSessionListener.class);

		this.registerServletFilter(servletContext, new SingleSignOutFilter());
		this.registerServletFilter(servletContext, new EAAuthenticationFilter());
		this.registerServletFilter(servletContext, new Cas20ProxyReceivingTicketValidationFilter());
		this.registerServletFilter(servletContext, new HttpServletRequestWrapperFilter());
		this.registerServletFilter(servletContext, new AssertionThreadLocalFilter());
	}

	@Override
	protected void customizeRegistration(Dynamic registration) {
		super.customizeRegistration(registration);
	}

	@Override
	protected javax.servlet.FilterRegistration.Dynamic registerServletFilter(ServletContext servletContext, Filter filter) {
		return super.registerServletFilter(servletContext, filter);
	}
}
